﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Word = Microsoft.Office.Interop.Word;
namespace PMSSys
{
    class exportController
    {
        private Patient pObject;
        private ICD icdObject;
        private patientController pcontroller;
        private icdController icdcontroller;

        
        public bool export(int p_id, patientController pcontroller,String CatchFileName)
        {
            try
            {

                MessageBox.Show("Saving to File Path: " + CatchFileName, "PMS Export System", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);

                icdcontroller = new icdController();
                pObject = new Patient();
                icdObject = new ICD();
                this.pcontroller = pcontroller;
                this.icdcontroller.DbConnect = pcontroller.DbConnect;
                pObject.PatientID = p_id;
                icdObject.PatientID = p_id;
                pcontroller.objectFiller(pObject);
                icdcontroller.objectFiller(icdObject);// ----------->> pagtapos na ni noy ung code niya,uncomment mo to
                //ready to go ka na after this kunin mo na sa icd and patient object ung mga data
                //MessageBox.Show(icdObject.Chiefcomplaint);

                Object OverloadParams = System.Reflection.Missing.Value;

                Object oTrue = true;
                Object oFalse = false;

                Word.Application CreateWord = new Word.Application();
                Word.Document AssembleDoc = new Word.Document();

                CreateWord.Visible = false;
                Object SavePath = System.Windows.Forms.Application.StartupPath + "\\PMSSysTemplate.dotx";
                Object FileSavePath = CatchFileName;

                AssembleDoc = CreateWord.Documents.Add(ref SavePath, ref OverloadParams, ref OverloadParams, ref OverloadParams);

                /*****************STATE DETECTION AND VALIDATION STARTS HERE**********************/
                if (icdObject.Cbcmch == true)
                {
                    object BMCbcMch = "CBCMCH";
                    AssembleDoc.Bookmarks.get_Item(ref BMCbcMch).Range.FormFields[1].CheckBox.Value = true;
                }

                if (icdObject.Cbcmchc == true)
                {
                    object BMCbcMchc = "CBCMCHC";
                    AssembleDoc.Bookmarks.get_Item(ref BMCbcMchc).Range.FormFields[1].CheckBox.Value = true;
                }


                if (icdObject.Cbcmcv == true)
                {
                    object BMCbcMcv = "CBCMCV";
                    AssembleDoc.Bookmarks.get_Item(ref BMCbcMcv).Range.FormFields[1].CheckBox.Value = true;
                }

                if (icdObject.Heent_crn_enlarged == true)
                {
                    object BMCLNEn = "CLNEnlarged";
                    AssembleDoc.Bookmarks.get_Item(ref BMCLNEn).Range.FormFields[1].CheckBox.Value = true;
                }

                if (icdObject.Heent_crn_normal == true)
                {
                    object BMCLNor = "CLNNormal";
                    AssembleDoc.Bookmarks.get_Item(ref BMCLNor).Range.FormFields[1].CheckBox.Value = true;
                }

                if (icdObject.Skinlesions == true)
                {
                    object BMDeLes = "DescLesion";
                    AssembleDoc.Bookmarks.get_Item(ref BMDeLes).Range.FormFields[1].CheckBox.Value = true;
                }

                if (icdObject.Endocrineabnormal == true)
                {
                    object BMEndocAbn = "EndocAbnormal";
                    AssembleDoc.Bookmarks.get_Item(ref BMEndocAbn).Range.FormFields[1].CheckBox.Value = true;
                }

                if (icdObject.Endocrinenormal == true)
                {
                    object BMEndocNor = "EndocNormal";
                    AssembleDoc.Bookmarks.get_Item(ref BMEndocNor).Range.FormFields[1].CheckBox.Value = true;
                }

                if (icdObject.Familyanemiabox == true)
                {
                    object BMFHAnemia = "FHAnemia";
                    AssembleDoc.Bookmarks.get_Item(ref BMFHAnemia).Range.FormFields[1].CheckBox.Value = true;
                }


                if (icdObject.Familycancerbox == true)
                {
                    object BMFHCancer = "FHCancer";
                    AssembleDoc.Bookmarks.get_Item(ref BMFHCancer).Range.FormFields[1].CheckBox.Value = true;
                }

                if (icdObject.Familyhemo == true)
                {
                    object BMFHHEmo = "FHHemo";
                    AssembleDoc.Bookmarks.get_Item(ref BMFHHEmo).Range.FormFields[1].CheckBox.Value = true;
                }

                if (icdObject.Familyothers == true)
                {
                    object BMFHOth = "FHOthers";
                    AssembleDoc.Bookmarks.get_Item(ref BMFHOth).Range.FormFields[1].CheckBox.Value = true;
                }

                if (icdObject.Familyvwf == true)
                {
                    object BMFHvWF = "FHvWF";
                    AssembleDoc.Bookmarks.get_Item(ref BMFHvWF).Range.FormFields[1].CheckBox.Value = true;
                }

                if (icdObject.Genitaliaabnormal == true)
                {
                    object BMGeniAbn = "GenitaliaAbnormal";
                    AssembleDoc.Bookmarks.get_Item(ref BMGeniAbn).Range.FormFields[1].CheckBox.Value = true;
                }

                if (icdObject.Genitalianormal == true)
                {
                    object BMGeniNor = "GenitaliaNormal";
                    AssembleDoc.Bookmarks.get_Item(ref BMGeniNor).Range.FormFields[1].CheckBox.Value = true;
                }

                if (icdObject.Hematologicnormal == true)
                {
                    object BMHemNor = "HematoNormal";
                    AssembleDoc.Bookmarks.get_Item(ref BMHemNor).Range.FormFields[1].CheckBox.Value = true;
                }

                if (icdObject.Hematologicabnormal == true)
                {
                    object BMHemAbn = "HematoAbnormal";
                    AssembleDoc.Bookmarks.get_Item(ref BMHemAbn).Range.FormFields[1].CheckBox.Value = true;
                }

                if (icdObject.Bcg == true)
                {
                    object BMImmBCG = "ImmunoBCG";
                    AssembleDoc.Bookmarks.get_Item(ref BMImmBCG).Range.FormFields[1].CheckBox.Value = true;
                }

                if (icdObject.Dtp == true)
                {
                    object BMImmDTP = "ImmunoDTP";
                    AssembleDoc.Bookmarks.get_Item(ref BMImmDTP).Range.FormFields[1].CheckBox.Value = true;
                }

                if (icdObject.Hepb == true)
                {
                    object BMImmHepaB = "ImmunoHepaB";
                    AssembleDoc.Bookmarks.get_Item(ref BMImmHepaB).Range.FormFields[1].CheckBox.Value = true;
                }

                if (icdObject.Hib == true)
                {
                    object BMImmHib = "ImmunoHib";
                    AssembleDoc.Bookmarks.get_Item(ref BMImmHib).Range.FormFields[1].CheckBox.Value = true;
                }

                if (icdObject.Hpv == true)
                {
                    object BMImmHPv = "ImmunoHPV";
                    AssembleDoc.Bookmarks.get_Item(ref BMImmHPv).Range.FormFields[1].CheckBox.Value = true;
                }

                if (icdObject.Mmr == true)
                {
                    object BMImmMMR = "ImmunoMMR";
                    AssembleDoc.Bookmarks.get_Item(ref BMImmMMR).Range.FormFields[1].CheckBox.Value = true;
                }

                if (icdObject.Opvipv == true)
                {
                    object BMImmOPVIPV = "ImmunoOPVIPV";
                    AssembleDoc.Bookmarks.get_Item(ref BMImmOPVIPV).Range.FormFields[1].CheckBox.Value = true;
                }

                if (icdObject.otherimmunizationcheck == true)
                {
                    object BMImmOthers = "ImmunoOthers";
                    AssembleDoc.Bookmarks.get_Item(ref BMImmOthers).Range.FormFields[1].CheckBox.Value = true;
                }

                if (icdObject.Vari == true)
                {
                    object BMImmVaric = "ImmunoVaricella";
                    AssembleDoc.Bookmarks.get_Item(ref BMImmVaric).Range.FormFields[1].CheckBox.Value = true;
                }

                if (icdObject.Chestrythm_irreg == true)
                {
                    object BMIrrRH = "IrregRhythmH";
                    AssembleDoc.Bookmarks.get_Item(ref BMIrrRH).Range.FormFields[1].CheckBox.Value = true;
                }

                if (icdObject.Chestrythm_murmur == true)
                {
                    object BMMurH = "MurmurH";
                    AssembleDoc.Bookmarks.get_Item(ref BMMurH).Range.FormFields[1].CheckBox.Value = true;
                }

                if (icdObject.Heent_conj_normal == true)
                {
                    object BMNoConj = "NormalConjunct";
                    AssembleDoc.Bookmarks.get_Item(ref BMNoConj).Range.FormFields[1].CheckBox.Value = true;
                }

                if (icdObject.Extremitiesnormal == true)
                {
                    object BMNorExtr = "NormalExtrem";
                    AssembleDoc.Bookmarks.get_Item(ref BMNorExtr).Range.FormFields[1].CheckBox.Value = true;
                }

                if (icdObject.Lungsnormal == true)
                {
                    object BMNorLun = "NormalLungs";
                    AssembleDoc.Bookmarks.get_Item(ref BMNorLun).Range.FormFields[1].CheckBox.Value = true;
                }

                if (icdObject.Heent_conj_pale == true)
                {
                    object BMPaleCon = "PaleConjunct";
                    AssembleDoc.Bookmarks.get_Item(ref BMPaleCon).Range.FormFields[1].CheckBox.Value = true;
                }

                if (icdObject.Pastallergybox == true)
                {
                    object BMPAllergy = "PAllergy";
                    AssembleDoc.Bookmarks.get_Item(ref BMPAllergy).Range.FormFields[1].CheckBox.Value = true;
                }

                if (icdObject.Pastillnessbox == true)
                {
                    object BMPIll = "PIllnesses";
                    AssembleDoc.Bookmarks.get_Item(ref BMPIll).Range.FormFields[1].CheckBox.Value = true;
                }

                if (icdObject.Pastmedicationsbox == true)
                {
                    object BMPPMed = "PMedications";
                    AssembleDoc.Bookmarks.get_Item(ref BMPPMed).Range.FormFields[1].CheckBox.Value = true;
                }

                if (icdObject.Perismearaniso == true)
                {
                    object BMPSAni = "PSAnisoc";
                    AssembleDoc.Bookmarks.get_Item(ref BMPSAni).Range.FormFields[1].CheckBox.Value = true;
                }

                if (icdObject.Perismearplatelets == true)
                {
                    object BMPSPla = "PSPlatelets";
                    AssembleDoc.Bookmarks.get_Item(ref BMPSPla).Range.FormFields[1].CheckBox.Value = true;
                }

                if (icdObject.Perismearpoikilo == true)
                {
                    object BMPSPoi = "PSPoikilo";
                    AssembleDoc.Bookmarks.get_Item(ref BMPSPoi).Range.FormFields[1].CheckBox.Value = true;
                }

                if (icdObject.Pastsurgerybox == true)
                {
                    object BMPSurg = "PSurgery";
                    AssembleDoc.Bookmarks.get_Item(ref BMPSurg).Range.FormFields[1].CheckBox.Value = true;
                }

                if (icdObject.Perismearwbc == true)
                {
                    object BMPswbc = "PSWBC";
                    AssembleDoc.Bookmarks.get_Item(ref BMPswbc).Range.FormFields[1].CheckBox.Value = true;
                }

                if (icdObject.Perismearrbc == true)
                {
                    object BMPRbc = "RBCPeriSmear";
                    AssembleDoc.Bookmarks.get_Item(ref BMPRbc).Range.FormFields[1].CheckBox.Value = true;
                }

                if (icdObject.Rectalabnormal == true)
                {
                    object BMRecAbn = "RectalAbnormal";
                    AssembleDoc.Bookmarks.get_Item(ref BMRecAbn).Range.FormFields[1].CheckBox.Value = true;
                }

                if (icdObject.Rectalnormal == true)
                {
                    object BMRecNor = "RectalNormal";
                    AssembleDoc.Bookmarks.get_Item(ref BMRecNor).Range.FormFields[1].CheckBox.Value = true;
                }

                if (icdObject.Heent_sclerae_normal == true)
                {
                    object BMScleNor = "ScleraeNormal";
                    AssembleDoc.Bookmarks.get_Item(ref BMScleNor).Range.FormFields[1].CheckBox.Value = true;
                }

                if (icdObject.Heent_sclerae_yellow == true)
                {
                    object BMScleYel = "ScleraeYellow";
                    AssembleDoc.Bookmarks.get_Item(ref BMScleYel).Range.FormFields[1].CheckBox.Value = true;
                }

                if (icdObject.Skinlesions == true)
                {
                    object BMSkinLes = "SkinLesion";
                    AssembleDoc.Bookmarks.get_Item(ref BMSkinLes).Range.FormFields[1].CheckBox.Value = true;
                }

                if (icdObject.Chestrythm_thrill == true)
                {
                    object BMThrillH = "ThrillH";
                    AssembleDoc.Bookmarks.get_Item(ref BMThrillH).Range.FormFields[1].CheckBox.Value = true;
                }

                if (icdObject.Heent_thyr_enlarged == true)
                {
                    object BMThyE = "ThyroidEnlarged";
                    AssembleDoc.Bookmarks.get_Item(ref BMThyE).Range.FormFields[1].CheckBox.Value = true;
                }

                if (icdObject.Heent_thyr_normal == true)
                {
                    object BMThyN = "ThyroidNormal";
                    AssembleDoc.Bookmarks.get_Item(ref BMThyN).Range.FormFields[1].CheckBox.Value = true;
                }

                if (icdObject.Heent_tonsils_beefy == true)
                {
                    object BMTonBfy = "TonsilsBeefy";
                    AssembleDoc.Bookmarks.get_Item(ref BMTonBfy).Range.FormFields[1].CheckBox.Value = true;
                }

                if (icdObject.Heent_tonsils_enlarged == true)
                {
                    object BMTonEnl = "TonsilsEnarged";
                    AssembleDoc.Bookmarks.get_Item(ref BMTonEnl).Range.FormFields[1].CheckBox.Value = true;
                }

                if (icdObject.Heent_tonsils_exudates == true)
                {
                    object BMTonEx = "TonsilsExudated";
                    AssembleDoc.Bookmarks.get_Item(ref BMTonEx).Range.FormFields[1].CheckBox.Value = true;
                }

                if (icdObject.Heent_tm_normal == true)
                {
                    object BMTonNor = "TonsilsNormal";
                    AssembleDoc.Bookmarks.get_Item(ref BMTonNor).Range.FormFields[1].CheckBox.Value = true;
                }



                AssembleDoc.SaveAs(ref FileSavePath, ref OverloadParams, ref OverloadParams, ref OverloadParams, ref OverloadParams, ref OverloadParams, ref OverloadParams, ref OverloadParams, ref OverloadParams, ref OverloadParams);

                int iReadFields;
                iReadFields = 0;

                foreach (Word.Field myMergeField in AssembleDoc.Fields)
                {
                    iReadFields++;
                    Word.Range rangeCode = myMergeField.Code;
                    String StreamText = rangeCode.Text;

                    if (StreamText.StartsWith(" MERGEFIELD"))
                    {
                        Int32 endMerge = StreamText.IndexOf("\\");
                        Int32 fieldNameLength = StreamText.Length - endMerge;
                        String fieldName = StreamText.Substring(11, endMerge - 11);
                        fieldName = fieldName.Trim();

                        if (fieldName == "PatientName")
                        {

                            String FirstStringer = pObject.FName;
                            String MiddleStringer = pObject.MName;
                            String LastStringer = pObject.LName;
                            String NameCatcher = FirstStringer + " " + MiddleStringer + " " + LastStringer;

                            myMergeField.Select();
                            CreateWord.Selection.TypeText(NameCatcher);
                        }




                        if (fieldName == "PatientSex")
                        {

                            myMergeField.Select();

                            if (string.IsNullOrEmpty(pObject.Sex))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(pObject.Sex);
                        }


                        if (fieldName == "PatAge")
                        {

                            int RecYear;
                            int extractPatYear;

                            DateTime receiveBDay = pObject.Birthday;
                            extractPatYear = receiveBDay.Year;


                            DateTime now = DateTime.Now;
                            RecYear = now.Year;

                            extractPatYear = RecYear - extractPatYear;

                            String ConvertString;
                            ConvertString = Convert.ToString(extractPatYear);

                            myMergeField.Select();
                            CreateWord.Selection.TypeText(ConvertString);
                        }


                        if (fieldName == "PatientBirthday")
                        {
                            String ConcatBDay;

                            DateTime chopper = pObject.Birthday;

                            String DivYear;
                            int DivMonth;

                            String retMonth = null;
                            String DivDay;

                            DivYear = Convert.ToString(chopper.Year);
                            //DivMonth = Convert.ToString(chopper.Month);
                            DivDay = Convert.ToString(chopper.Day);

                            DivMonth = Convert.ToInt16(chopper.Month);



                            if (DivMonth == 1)
                                retMonth = "January";
                            if (DivMonth == 2)
                                retMonth = "February";
                            if (DivMonth == 3)
                                retMonth = "March";
                            if (DivMonth == 4)
                                retMonth = "April";
                            if (DivMonth == 5)
                                retMonth = "May";
                            if (DivMonth == 6)
                                retMonth = "June";
                            if (DivMonth == 7)
                                retMonth = "July";
                            if (DivMonth == 8)
                                retMonth = "August";
                            if (DivMonth == 9)
                                retMonth = "September";
                            if (DivMonth == 10)
                                retMonth = "October";
                            if (DivMonth == 11)
                                retMonth = "November";
                            if (DivMonth == 12)
                                retMonth = "December";


                            ConcatBDay = retMonth + " " + DivDay + "," + " " + DivYear;


                            myMergeField.Select();
                            CreateWord.Selection.TypeText(ConcatBDay);
                        }

                        if (fieldName == "PatientAddress")
                        {
                            myMergeField.Select();


                            if (string.IsNullOrEmpty(pObject.Address))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(pObject.Address);

                        }

                        if (fieldName == "PatientTelNo")
                        {

                            myMergeField.Select();

                            if (string.IsNullOrEmpty(pObject.TelNo))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(pObject.TelNo);
                        }

                        if (fieldName == "PatientCPNo")
                        {
                            myMergeField.Select();

                            if (string.IsNullOrEmpty(pObject.CelNo))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(pObject.CelNo);
                        }

                        if (fieldName == "PatientFather")
                        {
                            myMergeField.Select();

                            if (string.IsNullOrEmpty(pObject.FatherName))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(pObject.FatherName);
                        }

                        if (fieldName == "PatFatherOcc")
                        {
                            myMergeField.Select();

                            if (string.IsNullOrEmpty(pObject.FatherOccu))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(pObject.FatherOccu);
                        }

                        if (fieldName == "PatientMother")
                        {
                            myMergeField.Select();
                            if (string.IsNullOrEmpty(pObject.MotherName))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(pObject.MotherName);
                        }


                        if (fieldName == "PatMotherOcc")
                        {
                            myMergeField.Select();

                            if (string.IsNullOrEmpty(pObject.MotherOccu))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(pObject.MotherOccu);
                        }


                        if (fieldName == "PatSiblings")
                        {
                            String CatchSiblingCount;

                            CatchSiblingCount = Convert.ToString(pObject.SiblingCount);


                            myMergeField.Select();

                            CreateWord.Selection.TypeText(CatchSiblingCount);
                        }

                        if (fieldName == "PatIncome")
                        {
                            String CatchIncome;
                            CatchIncome = Convert.ToString(pObject.AnnualInc);

                            myMergeField.Select();
                            CreateWord.Selection.TypeText(CatchIncome);
                        }

                        if (fieldName == "PatReferrer")
                        {
                            myMergeField.Select();

                            if (string.IsNullOrEmpty(pObject.Refferal))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(pObject.Refferal);
                        }

                        if (fieldName == "PCComplaint")
                        {
                            myMergeField.Select();

                            if (string.IsNullOrEmpty(icdObject.Chiefcomplaint))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Chiefcomplaint);
                        }

                        if (fieldName == "PatHPI")
                        {
                            myMergeField.Select();
                            if (string.IsNullOrEmpty(icdObject.Hpi))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Hpi);
                        }

                        if ((icdObject.otherimmunizationcheck) == true)
                        {
                            if (fieldName == "ImmunoOthers")
                            {
                                myMergeField.Select();

                                if (string.IsNullOrEmpty(icdObject.Otherimmunization))
                                    CreateWord.Selection.TypeText(" ");
                                else
                                    CreateWord.Selection.TypeText(icdObject.Otherimmunization);
                            }

                        }
                        else
                        {
                            if (fieldName == "ImmunoOthers")
                            {
                                myMergeField.Select();

                                CreateWord.Selection.TypeText(" ");

                            }
                        }


                        if ((icdObject.Familyanemiabox) == true)
                        {
                            if (fieldName == "AnemiaSpecify")
                            {
                                myMergeField.Select();

                                if (string.IsNullOrEmpty(icdObject.Familyanemia))
                                    CreateWord.Selection.TypeText(" ");
                                else
                                    CreateWord.Selection.TypeText(icdObject.Familyanemia);
                            }
                        }
                        else
                        {
                            if (fieldName == "AnemiaSpecify")
                            {
                                myMergeField.Select();

                                CreateWord.Selection.TypeText(" ");

                            }
                        }

                        if ((icdObject.Familyothers) == true)
                        {
                            if (fieldName == "FHOthersField")
                            {
                                myMergeField.Select();

                                if (string.IsNullOrEmpty(icdObject.Familyothersnotes))
                                    CreateWord.Selection.TypeText(" ");
                                else
                                    CreateWord.Selection.TypeText(icdObject.Familyothersnotes);
                            }

                        }
                        else
                        {
                            if (fieldName == "FHOthersField")
                            {
                                myMergeField.Select();

                                CreateWord.Selection.TypeText(" ");

                            }
                        }


                        if ((icdObject.Pastillnessbox) == true)
                        {
                            if (fieldName == "PIllnessesField")
                            {
                                myMergeField.Select();

                                if (string.IsNullOrEmpty(icdObject.Pastillness))
                                    CreateWord.Selection.TypeText(" ");
                                else
                                    CreateWord.Selection.TypeText(icdObject.Pastillness);
                            }
                        }
                        else
                        {
                            if (fieldName == "PIllnessesField")
                            {
                                myMergeField.Select();

                                CreateWord.Selection.TypeText(" ");

                            }
                        }


                        if ((icdObject.Pastsurgerybox) == true)
                        {
                            if (fieldName == "PSurgeryField")
                            {
                                myMergeField.Select();

                                if (string.IsNullOrEmpty(icdObject.Pastsurgery))
                                    CreateWord.Selection.TypeText(" ");
                                else
                                    CreateWord.Selection.TypeText(icdObject.Pastsurgery);
                            }
                        }
                        else
                        {
                            if (fieldName == "PSurgeryField")
                            {
                                myMergeField.Select();

                                CreateWord.Selection.TypeText(" ");

                            }
                        }


                        if ((icdObject.Pastmedicationsbox) == true)
                        {
                            if (fieldName == "PMedicationField")
                            {
                                myMergeField.Select();

                                if (string.IsNullOrEmpty(icdObject.Pastmedications))
                                    CreateWord.Selection.TypeText(" ");
                                else
                                    CreateWord.Selection.TypeText(icdObject.Pastmedications);

                            }
                        }
                        else
                        {
                            if (fieldName == "PMedicationField")
                            {
                                myMergeField.Select();

                                CreateWord.Selection.TypeText(" ");

                            }
                        }


                        if ((icdObject.Pastallergybox) == true)
                        {
                            if (fieldName == "PAllergyField")
                            {
                                myMergeField.Select();


                                if (string.IsNullOrEmpty(icdObject.Allergies))
                                    CreateWord.Selection.TypeText(" ");
                                else
                                    CreateWord.Selection.TypeText(icdObject.Allergies);
                            }
                        }
                        else
                        {
                            if (fieldName == "PAllergyField")
                            {
                                myMergeField.Select();

                                CreateWord.Selection.TypeText(" ");

                            }
                        }


                        if (fieldName == "EnviroHistory")
                        {
                            myMergeField.Select();

                            if (string.IsNullOrEmpty(icdObject.Envirohistory))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Envirohistory);
                        }
                        else
                        {
                            if (fieldName == "EnviroHistory")
                            {
                                myMergeField.Select();

                                CreateWord.Selection.TypeText(" ");

                            }
                        }


                        if (fieldName == "PsychoSocHistory")
                        {
                            myMergeField.Select();

                            if (string.IsNullOrEmpty(icdObject.Psychohistory))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Psychohistory);
                        }
                        else
                        {
                            if (fieldName == "PsychoHistory")
                            {
                                myMergeField.Select();

                                CreateWord.Selection.TypeText(" ");

                            }
                        }


                        if (fieldName == "PEFieldT")
                        {
                            myMergeField.Select();

                            if (string.IsNullOrEmpty(icdObject.Vitalt))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Vitalt);
                        }

                        if (fieldName == "PEWeight")
                        {
                            myMergeField.Select();

                            if (string.IsNullOrEmpty(icdObject.Vitalweight))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Vitalweight);
                        }

                        if (fieldName == "PEHeight")
                        {
                            myMergeField.Select();

                            if (string.IsNullOrEmpty(icdObject.Vitalheight))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Vitalheight);
                        }
                        if (fieldName == "PEBSAField")
                        {
                            myMergeField.Select();

                            if (string.IsNullOrEmpty(icdObject.Vitalbsa))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Vitalbsa);
                        }

                        if (fieldName == "PERRField")
                        {
                            myMergeField.Select();

                            if (string.IsNullOrEmpty(icdObject.Vitalrr))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Vitalrr);
                        }

                        if (fieldName == "PEBPField")
                        {
                            myMergeField.Select();

                            if (string.IsNullOrEmpty(icdObject.Vitalbp))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Vitalbp);
                        }

                        if (fieldName == "PEPainField")
                        {
                            myMergeField.Select();

                            if (string.IsNullOrEmpty(icdObject.Vitalpain))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Vitalpain);
                        }

                        if (fieldName == "PEPerfLevelField")
                        {
                            myMergeField.Select();

                            if (string.IsNullOrEmpty(icdObject.Vitalperform_lev))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Vitalperform_lev);
                        }

                        if (icdObject.Skinlesions == true)
                        {
                            if (fieldName == "LesionField")
                            {
                                myMergeField.Select();

                                if (string.IsNullOrEmpty(icdObject.Skinlesionsnotes))
                                    CreateWord.Selection.TypeText(" ");
                                else
                                    CreateWord.Selection.TypeText(icdObject.Skinlesionsnotes);
                            }
                            if (fieldName == "LesionsLocation")
                            {
                                myMergeField.Select();

                                if (string.IsNullOrEmpty(icdObject.Skinlocation))
                                    CreateWord.Selection.TypeText(" ");
                                else
                                    CreateWord.Selection.TypeText(icdObject.Skinlocation);
                            }
                        }
                        else
                        {
                            if (fieldName == "LesionsField")
                            {
                                myMergeField.Select();

                                CreateWord.Selection.TypeText(" ");

                            }
                            if (fieldName == "LesionsLocation")
                            {
                                myMergeField.Select();
                                CreateWord.Selection.TypeText(" ");
                            }

                        }


                        if (icdObject.Heent_thyr_enlarged == true)
                        {
                            if (fieldName == "EnlargedField")
                            {
                                myMergeField.Select();

                                if (string.IsNullOrEmpty(icdObject.Heent_thyr_enlargednotes))
                                    CreateWord.Selection.TypeText(" ");
                                else
                                    CreateWord.Selection.TypeText(icdObject.Heent_thyr_enlargednotes);
                            }

                        }
                        else
                        {
                            if (fieldName == "EnlargedField")
                            {
                                myMergeField.Select();

                                CreateWord.Selection.TypeText(" ");

                            }
                        }


                        if (icdObject.Heent_crn_enlarged == true)
                        {
                            if (fieldName == "CLNEnlarged")
                            {
                                myMergeField.Select();

                                if (string.IsNullOrEmpty(icdObject.Heent_crn_enlargednotes))
                                    CreateWord.Selection.TypeText(" ");
                                else
                                    CreateWord.Selection.TypeText(icdObject.Heent_crn_enlargednotes);
                            }


                        }
                        else
                        {
                            if (fieldName == "CLNEnlarged")
                            {
                                myMergeField.Select();

                                CreateWord.Selection.TypeText(" ");

                            }
                        }

                        if (icdObject.Lungsabnormal == true)
                        {
                            if (fieldName == "AbnormalLungDescri")
                            {
                                myMergeField.Select();

                                if (string.IsNullOrEmpty(icdObject.Lungsabnormalnotes))
                                    CreateWord.Selection.TypeText(" ");
                                else
                                    CreateWord.Selection.TypeText(icdObject.Lungsabnormalnotes);
                            }
                        }
                        else
                        {
                            if (fieldName == "AbnormalLungDescri")
                            {
                                myMergeField.Select();

                                CreateWord.Selection.TypeText(" ");

                            }
                        }

                        if (icdObject.Extremitiesabnormal == true)
                        {
                            if (fieldName == "AbnExtreDescri")
                            {
                                myMergeField.Select();


                                if (string.IsNullOrEmpty(icdObject.Extremitiesabnormalnotes))
                                    CreateWord.Selection.TypeText(" ");
                                else
                                    CreateWord.Selection.TypeText(icdObject.Extremitiesabnormalnotes);
                            }
                        }
                        else
                        {
                            if (fieldName == "AbnExtreDescri")
                            {
                                myMergeField.Select();

                                CreateWord.Selection.TypeText(" ");

                            }
                        }

                        if (icdObject.Rectalabnormal == true)
                        {
                            if (fieldName == "AbnRectDescri")
                            {
                                myMergeField.Select();

                                if (string.IsNullOrEmpty(icdObject.Lungsabnormalnotes))
                                    CreateWord.Selection.TypeText(" ");
                                else
                                    CreateWord.Selection.TypeText(icdObject.Lungsabnormalnotes);
                            }
                        }
                        else
                        {
                            if (fieldName == "AbnRectDescri")
                            {
                                myMergeField.Select();

                                CreateWord.Selection.TypeText(" ");

                            }
                        }


                        if (icdObject.Familycancerbox == true)
                        {
                            if (fieldName == "FHCancer")
                            {
                                myMergeField.Select();

                                if (string.IsNullOrEmpty(icdObject.Familycancer))
                                    CreateWord.Selection.TypeText(" ");
                                else
                                    CreateWord.Selection.TypeText(icdObject.Familycancer);
                            }
                        }
                        else
                        {
                            if (fieldName == "FHCancer")
                            {
                                myMergeField.Select();

                                CreateWord.Selection.TypeText(" ");

                            }
                        }




                        if (icdObject.Genitaliaabnormal == true)
                        {
                            if (fieldName == "AbnGeniDescri")
                            {
                                myMergeField.Select();

                                if (string.IsNullOrEmpty(icdObject.Genitaliaabnormalnotes))
                                    CreateWord.Selection.TypeText(" ");
                                else
                                    CreateWord.Selection.TypeText(icdObject.Genitaliaabnormalnotes);
                            }

                        }
                        else
                        {
                            if (fieldName == "AbnGeniDescri")
                            {
                                myMergeField.Select();

                                CreateWord.Selection.TypeText(" ");

                            }
                        }



                        if (icdObject.Hematologicabnormal == true)
                        {
                            if (fieldName == "AbnHemato")
                            {
                                myMergeField.Select();

                                if (string.IsNullOrEmpty(icdObject.Hematologicabnormalnotes))
                                    CreateWord.Selection.TypeText(" ");
                                else
                                    CreateWord.Selection.TypeText(icdObject.Hematologicabnormalnotes);
                            }
                        }
                        else
                        {
                            if (fieldName == "AbnHemato")
                            {
                                myMergeField.Select();

                                CreateWord.Selection.TypeText(" ");

                            }
                        }


                        if (icdObject.Endocrineabnormal == true)
                        {
                            if (fieldName == "AbnEndo")
                            {
                                myMergeField.Select();

                                if (string.IsNullOrEmpty(icdObject.Endocrineabnormalnotes))
                                    CreateWord.Selection.TypeText(" ");
                                else
                                    CreateWord.Selection.TypeText(icdObject.Endocrineabnormalnotes);
                            }
                        }
                        else
                        {
                            if (fieldName == "AbnEndo")
                            {
                                myMergeField.Select();

                                CreateWord.Selection.TypeText(" ");

                            }
                        }


                        if (icdObject.Cbcmcv == true)
                        {
                            if (fieldName == "CBC-MCV")
                            {
                                myMergeField.Select();

                                if (string.IsNullOrEmpty(icdObject.Cbcmcvnotes))
                                    CreateWord.Selection.TypeText(" ");
                                else
                                    CreateWord.Selection.TypeText(icdObject.Cbcmcvnotes);
                            }
                        }
                        else
                        {
                            if (fieldName == "CBC-MCV")
                            {
                                myMergeField.Select();
                                CreateWord.Selection.TypeText(" ");
                            }
                            
                        }


                        if (icdObject.Cbcmch == true)
                        {
                            if (fieldName == "CBC-MCH")
                            {
                                myMergeField.Select();

                                if (string.IsNullOrEmpty(icdObject.Cbcmchnotes))
                                    CreateWord.Selection.TypeText(" ");
                                else
                                    CreateWord.Selection.TypeText(icdObject.Cbcmchnotes);
                            }
                        }
                        else
                        {
                            if (fieldName == "CBC-MCH")
                            {
                                myMergeField.Select();

                                CreateWord.Selection.TypeText(" ");

                            }
                        }


                        if (icdObject.Cbcmchc == true)
                        {
                            if (fieldName == "CBC-MCHC")
                            {
                                myMergeField.Select();
                                if (string.IsNullOrEmpty(icdObject.Cbcmchcnotes))
                                    CreateWord.Selection.TypeText(" ");
                                else
                                    CreateWord.Selection.TypeText(icdObject.Cbcmchcnotes);
                            }
                        }
                        else
                        {
                            if (fieldName == "CBC-MCHC")
                            {
                                myMergeField.Select();

                                CreateWord.Selection.TypeText(" ");

                            }
                        }


                        if (icdObject.Perismearrbc == true)
                        {
                            if (fieldName == "PSRBCField")
                            {
                                myMergeField.Select();

                                if (string.IsNullOrEmpty(icdObject.Perismearrbcnotes))
                                    CreateWord.Selection.TypeText(" ");
                                else
                                    CreateWord.Selection.TypeText(icdObject.Perismearrbcnotes);
                            }
                        }
                        else
                        {
                            if (fieldName == "PSRBCField")
                            {
                                myMergeField.Select();

                                CreateWord.Selection.TypeText(" ");

                            }
                        }


                        if (icdObject.Perismearpoikilo == true)
                        {
                            if (fieldName == "PSPoikiloField")
                            {
                                myMergeField.Select();

                                if (string.IsNullOrEmpty(icdObject.Perismearpoikilonotes))
                                    CreateWord.Selection.TypeText(" ");
                                else
                                    CreateWord.Selection.TypeText(icdObject.Perismearpoikilonotes);
                            }
                        }
                        else
                        {
                            if (fieldName == "PSPoikiloField")
                            {
                                myMergeField.Select();

                                CreateWord.Selection.TypeText(" ");

                            }
                        }


                        if (icdObject.Perismearrbc == true)
                        {
                            if (fieldName == "PWBC-B")
                            {
                                myMergeField.Select();

                                if (string.IsNullOrEmpty(icdObject.Perismearb))
                                    CreateWord.Selection.TypeText(" ");
                                else
                                    CreateWord.Selection.TypeText(icdObject.Perismearb);
                            }
                            if (fieldName == "PWBC-N")
                            {

                                myMergeField.Select();

                                if (string.IsNullOrEmpty(icdObject.Perismearn))
                                    CreateWord.Selection.TypeText(" ");
                                else
                                    CreateWord.Selection.TypeText(icdObject.Perismearn);
                            }
                            if (fieldName == "PWBC-L")
                            {
                                myMergeField.Select();

                                if (string.IsNullOrEmpty(icdObject.Perismearl))
                                    CreateWord.Selection.TypeText(" ");
                                else
                                    CreateWord.Selection.TypeText(icdObject.Perismearl);
                            }

                            if (fieldName == "PWBC-B2")
                            {
                                myMergeField.Select();

                                if (string.IsNullOrEmpty(icdObject.Perismear2b))
                                    CreateWord.Selection.TypeText(" ");
                                else
                                    CreateWord.Selection.TypeText(icdObject.Perismear2b);
                            }

                            if (fieldName == "PWBC-E")
                            {

                                myMergeField.Select();

                                if (string.IsNullOrEmpty(icdObject.Perismeare))
                                    CreateWord.Selection.TypeText(" ");
                                else
                                    CreateWord.Selection.TypeText(icdObject.Perismeare);
                            }

                            if (fieldName == "PWBC-M")
                            {

                                myMergeField.Select();

                                if (string.IsNullOrEmpty(icdObject.Perismearm))
                                    CreateWord.Selection.TypeText(" ");
                                else
                                    CreateWord.Selection.TypeText(icdObject.Perismearm);
                            }

                            if (fieldName == "WBC-Blast")
                            {

                                myMergeField.Select();

                                if (string.IsNullOrEmpty(icdObject.Perismearblast))
                                    CreateWord.Selection.TypeText(" ");
                                else
                                    CreateWord.Selection.TypeText(icdObject.Perismearblast);
                            }
                            if (fieldName == "WBCBlastField")
                            {

                                myMergeField.Select();

                                if (string.IsNullOrEmpty(icdObject.Perismearblast))
                                    CreateWord.Selection.TypeText(" ");
                                else
                                    CreateWord.Selection.TypeText(icdObject.Perismearblast);
                            }
                        }
                        else
                        {
                            if (fieldName == "PWBC-B")
                            {
                                myMergeField.Select();
                                CreateWord.Selection.TypeText(" ");
                              
                            }
                            if (fieldName == "PWBC-N")
                            {

                                myMergeField.Select();

                               
                                    CreateWord.Selection.TypeText(" ");
                              
                            }
                            if (fieldName == "PWBC-L")
                            {
                                myMergeField.Select();

                               
                                    CreateWord.Selection.TypeText(" ");
                              
                            }

                            if (fieldName == "PWBC-B2")
                            {
                                myMergeField.Select();

                                    CreateWord.Selection.TypeText(" ");
                      
                            }

                            if (fieldName == "PWBC-E")
                            {

                                myMergeField.Select();

                              
                                    CreateWord.Selection.TypeText(" ");
                               
                            }

                            if (fieldName == "PWBC-M")
                            {

                                myMergeField.Select();

                                    CreateWord.Selection.TypeText(" ");
                               
                            }

                            if (fieldName == "WBC-Blast")
                            {

                                myMergeField.Select();

                                    CreateWord.Selection.TypeText(" ");
                              
                            }
                            if (fieldName == "WBCBlastField")
                            {

                                myMergeField.Select();

                                    CreateWord.Selection.TypeText(" ");
                            
                            }
                        }


                        if (icdObject.Perismearplatelets == true)
                        {
                            if (fieldName == "P-Adeq")
                            {
                                myMergeField.Select();

                                if (string.IsNullOrEmpty(icdObject.Perismearadeq))
                                    CreateWord.Selection.TypeText(" ");
                                else
                                    CreateWord.Selection.TypeText(icdObject.Perismearadeq);
                            }
                            if (fieldName == "P-Inc")
                            {

                                myMergeField.Select();

                                if (string.IsNullOrEmpty(icdObject.Perismearinc))
                                    CreateWord.Selection.TypeText(" ");
                                else
                                    CreateWord.Selection.TypeText(icdObject.Perismearinc);
                            }
                            if (fieldName == "P-Dec")
                            {
                                myMergeField.Select();

                                if (string.IsNullOrEmpty(icdObject.Perismeardec))
                                    CreateWord.Selection.TypeText(" ");
                                else
                                    CreateWord.Selection.TypeText(icdObject.Perismeardec);
                            }

                            if (fieldName == "Plat-Macro")
                            {
                                myMergeField.Select();

                                if (string.IsNullOrEmpty(icdObject.Perismearmacro))
                                    CreateWord.Selection.TypeText(" ");
                                else
                                    CreateWord.Selection.TypeText(icdObject.Perismearmacro);
                            }

                            if (fieldName == "Plat-Micro")
                            {

                                myMergeField.Select();

                                if (string.IsNullOrEmpty(icdObject.Perismearmicro))
                                    CreateWord.Selection.TypeText(" ");
                                else
                                    CreateWord.Selection.TypeText(icdObject.Perismearmicro);
                            }

                        } else
                          
                            {
                                if (fieldName == "P-Adeq")
                                {
                                    myMergeField.Select();

                                        CreateWord.Selection.TypeText(" ");
                                    
                                }
                                if (fieldName == "P-Inc")
                                {

                                    myMergeField.Select();

                                        CreateWord.Selection.TypeText(" ");
                                }
                                if (fieldName == "P-Dec")
                                {
                                    myMergeField.Select();
                                        CreateWord.Selection.TypeText(" ");
                                }

                                if (fieldName == "Plat-Macro")
                                {
                                    myMergeField.Select();

                                        CreateWord.Selection.TypeText(" ");
                                }

                                if (fieldName == "Plat-Micro")
                                {

                                    myMergeField.Select();

              
                                        CreateWord.Selection.TypeText(" ");
                                   
                                }

                            }


                        /******************************************************************/

                        if (fieldName == "PEOthers")
                        {
                            myMergeField.Select();

                            if (string.IsNullOrEmpty(icdObject.Phys_others))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Phys_others);
                        }
                        if (fieldName == "CBC-Hgb")
                        {
                            myMergeField.Select();

                            if (string.IsNullOrEmpty(icdObject.Cbchgb))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Cbchgb);
                        }
                        if (fieldName == "CBC-Hct")
                        {
                            myMergeField.Select();

                            if (string.IsNullOrEmpty(icdObject.Cbchct))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Cbchct);
                        }
                        if (fieldName == "CBC-WBC")
                        {
                            myMergeField.Select();

                            if (string.IsNullOrEmpty(icdObject.Cbcwbc))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Cbcwbc);
                        }
                        if (fieldName == "CBC-Stabs")
                        {
                            myMergeField.Select();

                            if (string.IsNullOrEmpty(icdObject.Cbcstabs))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Cbcstabs);
                        }
                        if (fieldName == "CBC-Seg")
                        {
                            myMergeField.Select();

                            if (string.IsNullOrEmpty(icdObject.Cbcseg))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Cbcseg);
                        }
                        if (fieldName == "CBC-L")
                        {
                            myMergeField.Select();

                            if (string.IsNullOrEmpty(icdObject.Cbcl))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Cbcl);
                        }
                        if (fieldName == "CBC-M")
                        {
                            myMergeField.Select();

                            if (string.IsNullOrEmpty(icdObject.Cbcm))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Cbcm);
                        }
                        if (fieldName == "CBC-E")
                        {
                            myMergeField.Select();

                            if (string.IsNullOrEmpty(icdObject.Cbce))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Cbce);
                        }
                        if (fieldName == "CBC-Blast")
                        {
                            myMergeField.Select();

                            if (string.IsNullOrEmpty(icdObject.Cbcblast))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Cbcblast);
                        }
                        if (fieldName == "CBC-Plat")
                        {
                            myMergeField.Select();

                            if (string.IsNullOrEmpty(icdObject.Cbcplatelet))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Cbcplatelet);
                        }
                        if (fieldName == "PSInterpField")
                        {
                            myMergeField.Select();

                            if (string.IsNullOrEmpty(icdObject.Perismearinterpre))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Perismearinterpre);
                        }

                        if (fieldName == "COA-IBT")
                        {
                            myMergeField.Select();

                            if (string.IsNullOrEmpty(icdObject.Coagprofblledtime))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Coagprofblledtime);
                        }
                        if (fieldName == "COA-LWCT")
                        {
                            myMergeField.Select();

                            if (string.IsNullOrEmpty(icdObject.Coagprofclottime))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Coagprofclottime);
                        }
                        if (fieldName == "COA-PT")
                        {
                            myMergeField.Select();

                            if (string.IsNullOrEmpty(icdObject.Coagprofpt))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Coagprofpt);
                        }
                        if (fieldName == "COA-aPTT")
                        {
                            myMergeField.Select();

                            if (string.IsNullOrEmpty(icdObject.Coagprofaptt))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Coagprofaptt);
                        }

                        if (fieldName == "COA-FA-8")
                        {
                            myMergeField.Select();

                            if (string.IsNullOrEmpty(icdObject.Coagprofviii))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Coagprofviii);
                        }

                        if (fieldName == "COA-FA-9")
                        {
                            myMergeField.Select();

                            if (string.IsNullOrEmpty(icdObject.Coagprofix))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Coagprofix);
                        }

                        if (fieldName == "COA-Fibro")
                        {
                            myMergeField.Select();
                            if (string.IsNullOrEmpty(icdObject.Coagproffibri))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Coagproffibri);
                        }

                        if (fieldName == "COA-Dimers")
                        {
                            myMergeField.Select();
                            if (string.IsNullOrEmpty(icdObject.Coagprofdmmers))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Coagprofdmmers);
                        }

                        if (fieldName == "COA-Others")
                        {
                            myMergeField.Select();
                            if (string.IsNullOrEmpty(icdObject.Coagprofothers))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Coagprofothers);
                        }

                        if (fieldName == "COA-FDP")
                        {
                            myMergeField.Select();
                            if (string.IsNullOrEmpty(icdObject.Coagproffdp))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Coagproffdp);
                        }
                        if (fieldName == "PLA-Aggreg")
                        {
                            myMergeField.Select();
                            if (string.IsNullOrEmpty(icdObject.Plateaggregationtests))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Plateaggregationtests);
                        }

                        if (fieldName == "Hemo-Electro")
                        {
                            myMergeField.Select();
                            if (string.IsNullOrEmpty(icdObject.Hemoglobinelectronotes))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Hemoglobinelectronotes);
                        }


                        if (fieldName == "BMS-Granulo")
                        {
                            myMergeField.Select();
                            if (string.IsNullOrEmpty(icdObject.Bonemsmgranulopoiesis))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Bonemsmgranulopoiesis);
                        }

                        if (fieldName == "BMS-Megakaryo")
                        {
                            myMergeField.Select();
                            if (string.IsNullOrEmpty(icdObject.Bonemsmmegakaryopoiesis))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Bonemsmmegakaryopoiesis);
                        }

                        if (fieldName == "BMS-0thers")
                        {
                            myMergeField.Select();
                            if (string.IsNullOrEmpty(icdObject.Bonemsmothers))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Bonemsmothers);
                        }
                        if (fieldName == "BMS-Interp")
                        {
                            myMergeField.Select();

                            if (string.IsNullOrEmpty(icdObject.Bonemsminterpretations))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Bonemsminterpretations);
                        }

                        if (fieldName == "BMS-Erythro")
                        {
                            myMergeField.Select();

                            if (string.IsNullOrEmpty(icdObject.Bonemsmerythropoiesis))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Bonemsmerythropoiesis);
                        }

                        if (fieldName == "BMS-Others")
                        {
                            myMergeField.Select();

                            if (string.IsNullOrEmpty(icdObject.Bonemsmothers))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Bonemsmothers);
                        }



                        if (fieldName == "BMB/CB")
                        {
                            myMergeField.Select();

                            if (string.IsNullOrEmpty(icdObject.Bonemrbiopsynotes))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Bonemrbiopsynotes);
                        }

                        if (fieldName == "HISTO-REP")
                        {
                            myMergeField.Select();

                            if (string.IsNullOrEmpty(icdObject.Histopathologynotes))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Histopathologynotes);
                        }
                        if (fieldName == "CytoOthers")
                        {
                            myMergeField.Select();

                            if (string.IsNullOrEmpty(icdObject.Cytochemothers))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Cytochemothers);
                        }

                        if (fieldName == "CD3")
                        {
                            myMergeField.Select();

                            if (string.IsNullOrEmpty(icdObject.Immunophenocd3))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Immunophenocd3);
                        }
                        if (fieldName == "CD5")
                        {
                            myMergeField.Select();

                            if (string.IsNullOrEmpty(icdObject.Immunophenocd5))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Immunophenocd5);
                        }
                        if (fieldName == "CD7")
                        {
                            myMergeField.Select();


                            if (string.IsNullOrEmpty(icdObject.Immunophenocd7))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Immunophenocd7);
                        }
                        if (fieldName == "CD10")
                        {
                            myMergeField.Select();


                            if (string.IsNullOrEmpty(icdObject.Immunophenocd10))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Immunophenocd10);
                        }
                        if (fieldName == "antiHLADR")
                        {
                            myMergeField.Select();


                            if (string.IsNullOrEmpty(icdObject.Immunophenoantihladr))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Immunophenoantihladr);
                        }
                        if (fieldName == "CD13")
                        {
                            myMergeField.Select();


                            if (string.IsNullOrEmpty(icdObject.Immunophenocd13))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Immunophenocd13);
                        }
                        if (fieldName == "CD19")
                        {
                            myMergeField.Select();


                            if (string.IsNullOrEmpty(icdObject.Immunophenocd19))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Immunophenocd19);
                        }
                        if (fieldName == "CD20")
                        {
                            myMergeField.Select();


                            if (string.IsNullOrEmpty(icdObject.Immunophenocd20))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Immunophenocd20);
                        }
                        if (fieldName == "CD22")
                        {
                            myMergeField.Select();

                            if (string.IsNullOrEmpty(icdObject.Immunophenocd22))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Immunophenocd22);
                        }
                        if (fieldName == "CD33")
                        {
                            myMergeField.Select();


                            if (string.IsNullOrEmpty(icdObject.Immunophenocd33))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Immunophenocd33);
                        }

                        if (fieldName == "CD34")
                        {
                            myMergeField.Select();


                            if (string.IsNullOrEmpty(icdObject.Immunophenocd34))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Immunophenocd34);
                        }


                        if (fieldName == "Chromo-Study")
                        {
                            myMergeField.Select();


                            if (string.IsNullOrEmpty(icdObject.Chromonotes))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Chromonotes);
                        }
                        if (fieldName == "BoneScan")
                        {
                            myMergeField.Select();


                            if (string.IsNullOrEmpty(icdObject.Bonescannotes))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Bonescannotes);
                        }
                        if (fieldName == "ChestXRay")
                        {
                            myMergeField.Select();


                            if (string.IsNullOrEmpty(icdObject.Chestxraynotes))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Chestxraynotes);
                        }
                        if (fieldName == "OthersBelow")
                        {
                            myMergeField.Select();



                            if (string.IsNullOrEmpty(icdObject.Othernotes))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Othernotes);
                        }
                        if (fieldName == "ImpreDiag")
                        {
                            myMergeField.Select();

                            if (string.IsNullOrEmpty(icdObject.Impressiondiagnosis))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Impressiondiagnosis);
                        }
                        if (fieldName == "Reti-Act")
                        {
                            myMergeField.Select();

                            if (string.IsNullOrEmpty(icdObject.Cbcreticulyte_count))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Cbcreticulyte_count);
                        }

                        if (fieldName == "Reti-RPI")
                        {
                            myMergeField.Select();

                            if (string.IsNullOrEmpty(icdObject.Cbcrpi))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Cbcrpi);
                        }

                        if (fieldName == "Cyto-PAS")
                        {
                            myMergeField.Select();

                            if (string.IsNullOrEmpty(icdObject.Cytochempas))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Cytochempas);
                        }

                        if (fieldName == "Cyto-MPO")
                        {
                            myMergeField.Select();

                            if (string.IsNullOrEmpty(icdObject.Cytochemmpo))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Cytochemmpo);
                        }

                        if (fieldName == "Cyto-SBB")
                        {
                            myMergeField.Select();
                            if (string.IsNullOrEmpty(icdObject.Cytochemsbb))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Cytochemsbb);
                        }

                        if (fieldName == "ImmunoFlowOthers")
                        {
                            myMergeField.Select();
                            if (string.IsNullOrEmpty(icdObject.Immunophenoothers))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Immunophenoothers);
                        }

                        if (fieldName == "PerformanceLevel")
                        {
                            myMergeField.Select();
                            if (string.IsNullOrEmpty(icdObject.Vitalperform_lev))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Vitalperform_lev);
                        }

                        if (fieldName == "CH-SMR")
                        {
                            myMergeField.Select();
                            if(string.IsNullOrEmpty(icdObject.Chestbreast_smr))
                                CreateWord.Selection.TypeText(" ");
                            else
                                CreateWord.Selection.TypeText(icdObject.Chestbreast_smr);

                        }

                        if (fieldName == "RE-SMR")
                        {
                            myMergeField.Select();
                            if (string.IsNullOrEmpty(icdObject.Smrrating))
                            {
                                CreateWord.Selection.TypeText(" ");
                            }
                            else
                                CreateWord.Selection.TypeText(icdObject.Smrrating);
                        }

                        if (fieldName == "PEHRField")
                        {
                            myMergeField.Select();

                            if (string.IsNullOrEmpty(icdObject.Vitalhr))
                            {
                                CreateWord.Selection.TypeText(" ");
                            }
                            else
                                CreateWord.Selection.TypeText(icdObject.Vitalhr);

                        }



                        /**DATES**/
                        if (fieldName == "BiopsyDate")
                        {

                            myMergeField.Select();

                            String ConcatBiopsy;

                            DateTime chopper = icdObject.Bonemrbiopsydate;

                            String DivYear;
                            int DivMonth;

                            String retMonth = null;
                            String DivDay;

                            DivYear = Convert.ToString(chopper.Year);
                            //DivMonth = Convert.ToString(chopper.Month);
                            DivDay = Convert.ToString(chopper.Day);

                            DivMonth = Convert.ToInt16(chopper.Month);



                            if (DivMonth == 1)
                                retMonth = "January";
                            if (DivMonth == 2)
                                retMonth = "February";
                            if (DivMonth == 3)
                                retMonth = "March";
                            if (DivMonth == 4)
                                retMonth = "April";
                            if (DivMonth == 5)
                                retMonth = "May";
                            if (DivMonth == 6)
                                retMonth = "June";
                            if (DivMonth == 7)
                                retMonth = "July";
                            if (DivMonth == 8)
                                retMonth = "August";
                            if (DivMonth == 9)
                                retMonth = "September";
                            if (DivMonth == 10)
                                retMonth = "October";
                            if (DivMonth == 11)
                                retMonth = "November";
                            if (DivMonth == 12)
                                retMonth = "December";


                            ConcatBiopsy = retMonth + " " + DivDay + "," + " " + DivYear;



                            CreateWord.Selection.TypeText(ConcatBiopsy);

                        }

                        if (fieldName == "HistoPathDate")
                        {

                            String ConcatHistoDate;

                            if (string.IsNullOrEmpty(Convert.ToString(icdObject.Bonemrbiopsydate)))
                            {
                                CreateWord.Selection.TypeText(" ");
                            }
                            else
                            {
                                DateTime chopper = icdObject.Histopathologydate;

                                String DivYear;
                                int DivMonth;

                                String retMonth = null;
                                String DivDay;

                                DivYear = Convert.ToString(chopper.Year);
                                //DivMonth = Convert.ToString(chopper.Month);
                                DivDay = Convert.ToString(chopper.Day);

                                DivMonth = Convert.ToInt16(chopper.Month);



                                if (DivMonth == 1)
                                    retMonth = "January";
                                if (DivMonth == 2)
                                    retMonth = "February";
                                if (DivMonth == 3)
                                    retMonth = "March";
                                if (DivMonth == 4)
                                    retMonth = "April";
                                if (DivMonth == 5)
                                    retMonth = "May";
                                if (DivMonth == 6)
                                    retMonth = "June";
                                if (DivMonth == 7)
                                    retMonth = "July";
                                if (DivMonth == 8)
                                    retMonth = "August";
                                if (DivMonth == 9)
                                    retMonth = "September";
                                if (DivMonth == 10)
                                    retMonth = "October";
                                if (DivMonth == 11)
                                    retMonth = "November";
                                if (DivMonth == 12)
                                    retMonth = "December";


                                ConcatHistoDate = retMonth + " " + DivDay + "," + " " + DivYear;


                                myMergeField.Select();
                                CreateWord.Selection.TypeText(ConcatHistoDate);
                            }
                        }


                        if (fieldName == "CytoDate")
                        {
                            String ConcatCytoDate;

                            myMergeField.Select();

                            if (string.IsNullOrEmpty(Convert.ToString(icdObject.Cytochemdate)))
                            {
                                CreateWord.Selection.TypeText(" ");
                            }
                            else
                            {
                                DateTime chopper = icdObject.Cytochemdate;

                                String DivYear;
                                int DivMonth;

                                String retMonth = null;
                                String DivDay;

                                DivYear = Convert.ToString(chopper.Year);
                                //DivMonth = Convert.ToString(chopper.Month);
                                DivDay = Convert.ToString(chopper.Day);

                                DivMonth = Convert.ToInt16(chopper.Month);



                                if (DivMonth == 1)
                                    retMonth = "January";
                                if (DivMonth == 2)
                                    retMonth = "February";
                                if (DivMonth == 3)
                                    retMonth = "March";
                                if (DivMonth == 4)
                                    retMonth = "April";
                                if (DivMonth == 5)
                                    retMonth = "May";
                                if (DivMonth == 6)
                                    retMonth = "June";
                                if (DivMonth == 7)
                                    retMonth = "July";
                                if (DivMonth == 8)
                                    retMonth = "August";
                                if (DivMonth == 9)
                                    retMonth = "September";
                                if (DivMonth == 10)
                                    retMonth = "October";
                                if (DivMonth == 11)
                                    retMonth = "November";
                                if (DivMonth == 12)
                                    retMonth = "December";


                                ConcatCytoDate = retMonth + " " + DivDay + "," + " " + DivYear;



                                CreateWord.Selection.TypeText(ConcatCytoDate);
                            }
                        }

                        if (fieldName == "Chromo-Date")
                        {
                            String ConcatChromoDate;

                            myMergeField.Select();

                            if (string.IsNullOrEmpty(Convert.ToString(icdObject.Chromodate)))
                            {
                                CreateWord.Selection.TypeText(" ");
                            }
                            else
                            {
                                DateTime chopper = icdObject.Chromodate;

                                String DivYear;
                                int DivMonth;

                                String retMonth = null;
                                String DivDay;

                                DivYear = Convert.ToString(chopper.Year);
                                //DivMonth = Convert.ToString(chopper.Month);
                                DivDay = Convert.ToString(chopper.Day);

                                DivMonth = Convert.ToInt16(chopper.Month);



                                if (DivMonth == 1)
                                    retMonth = "January";
                                if (DivMonth == 2)
                                    retMonth = "February";
                                if (DivMonth == 3)
                                    retMonth = "March";
                                if (DivMonth == 4)
                                    retMonth = "April";
                                if (DivMonth == 5)
                                    retMonth = "May";
                                if (DivMonth == 6)
                                    retMonth = "June";
                                if (DivMonth == 7)
                                    retMonth = "July";
                                if (DivMonth == 8)
                                    retMonth = "August";
                                if (DivMonth == 9)
                                    retMonth = "September";
                                if (DivMonth == 10)
                                    retMonth = "October";
                                if (DivMonth == 11)
                                    retMonth = "November";
                                if (DivMonth == 12)
                                    retMonth = "December";


                                ConcatChromoDate = retMonth + " " + DivDay + "," + " " + DivYear;


                                CreateWord.Selection.TypeText(ConcatChromoDate);
                            }
                        }

                        if (fieldName == "BoneScanDate")
                        {
                            myMergeField.Select();

                            if (string.IsNullOrEmpty(Convert.ToString(icdObject.Bonescandate)))
                            {
                                CreateWord.Selection.TypeText(" ");
                            }
                            else
                            {
                                String ConcatBSDate;

                                DateTime chopper = icdObject.Bonescandate;

                                String DivYear;
                                int DivMonth;

                                String retMonth = null;
                                String DivDay;

                                DivYear = Convert.ToString(chopper.Year);
                                //DivMonth = Convert.ToString(chopper.Month);
                                DivDay = Convert.ToString(chopper.Day);

                                DivMonth = Convert.ToInt16(chopper.Month);



                                if (DivMonth == 1)
                                    retMonth = "January";
                                if (DivMonth == 2)
                                    retMonth = "February";
                                if (DivMonth == 3)
                                    retMonth = "March";
                                if (DivMonth == 4)
                                    retMonth = "April";
                                if (DivMonth == 5)
                                    retMonth = "May";
                                if (DivMonth == 6)
                                    retMonth = "June";
                                if (DivMonth == 7)
                                    retMonth = "July";
                                if (DivMonth == 8)
                                    retMonth = "August";
                                if (DivMonth == 9)
                                    retMonth = "September";
                                if (DivMonth == 10)
                                    retMonth = "October";
                                if (DivMonth == 11)
                                    retMonth = "November";
                                if (DivMonth == 12)
                                    retMonth = "December";


                                ConcatBSDate = retMonth + " " + DivDay + "," + " " + DivYear;



                                CreateWord.Selection.TypeText(ConcatBSDate);
                            }
                        }

                        if (fieldName == "ChestXRayDate")
                        {
                            String ConcatCXD;

                            myMergeField.Select();

                            if (string.IsNullOrEmpty(Convert.ToString(icdObject.Chestxraydate)))
                            {
                                CreateWord.Selection.TypeText(" ");
                            }


                            DateTime chopper = icdObject.Chestxraydate;

                            String DivYear;
                            int DivMonth;

                            String retMonth = null;
                            String DivDay;

                            DivYear = Convert.ToString(chopper.Year);
                            //DivMonth = Convert.ToString(chopper.Month);
                            DivDay = Convert.ToString(chopper.Day);

                            DivMonth = Convert.ToInt16(chopper.Month);



                            if (DivMonth == 1)
                                retMonth = "January";
                            if (DivMonth == 2)
                                retMonth = "February";
                            if (DivMonth == 3)
                                retMonth = "March";
                            if (DivMonth == 4)
                                retMonth = "April";
                            if (DivMonth == 5)
                                retMonth = "May";
                            if (DivMonth == 6)
                                retMonth = "June";
                            if (DivMonth == 7)
                                retMonth = "July";
                            if (DivMonth == 8)
                                retMonth = "August";
                            if (DivMonth == 9)
                                retMonth = "September";
                            if (DivMonth == 10)
                                retMonth = "October";
                            if (DivMonth == 11)
                                retMonth = "November";
                            if (DivMonth == 12)
                                retMonth = "December";


                            ConcatCXD = retMonth + " " + DivDay + "," + " " + DivYear;


                            CreateWord.Selection.TypeText(ConcatCXD);
                        }

                        if (fieldName == "ImmunoPhenoDate")
                        {
                            String ConcatIPD;

                            myMergeField.Select();

                            if (string.IsNullOrEmpty(Convert.ToString(icdObject.Immunophenodate)))
                            {
                                CreateWord.Selection.TypeText(" ");
                            }
                            else
                            {

                                DateTime chopper = icdObject.Immunophenodate;

                                String DivYear;
                                int DivMonth;

                                String retMonth = null;
                                String DivDay;

                                DivYear = Convert.ToString(chopper.Year);
                                //DivMonth = Convert.ToString(chopper.Month);
                                DivDay = Convert.ToString(chopper.Day);

                                DivMonth = Convert.ToInt16(chopper.Month);



                                if (DivMonth == 1)
                                    retMonth = "January";
                                if (DivMonth == 2)
                                    retMonth = "February";
                                if (DivMonth == 3)
                                    retMonth = "March";
                                if (DivMonth == 4)
                                    retMonth = "April";
                                if (DivMonth == 5)
                                    retMonth = "May";
                                if (DivMonth == 6)
                                    retMonth = "June";
                                if (DivMonth == 7)
                                    retMonth = "July";
                                if (DivMonth == 8)
                                    retMonth = "August";
                                if (DivMonth == 9)
                                    retMonth = "September";
                                if (DivMonth == 10)
                                    retMonth = "October";
                                if (DivMonth == 11)
                                    retMonth = "November";
                                if (DivMonth == 12)
                                    retMonth = "December";


                                ConcatIPD = retMonth + " " + DivDay + "," + " " + DivYear;


                                myMergeField.Select();
                                CreateWord.Selection.TypeText(ConcatIPD);
                            }
                        }

                    }



                }
                MessageBox.Show("Please take a moment until all files are saved.", "PMS Export System", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                AssembleDoc.Close(ref OverloadParams, ref OverloadParams, ref OverloadParams);

                return true;
            }
            catch (Exception e)
            {
                MessageBox.Show(e.StackTrace);
                return false;
            }
        }

    }
}
